package com.zjcloud.academic.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zjcloud.common.annotation.Log;
import com.zjcloud.common.core.controller.BaseController;
import com.zjcloud.common.core.domain.AjaxResult;
import com.zjcloud.common.enums.BusinessType;
import com.zjcloud.academic.domain.AcScheduleTask;
import com.zjcloud.academic.service.IAcScheduleTaskService;
import com.zjcloud.common.utils.poi.ExcelUtil;
import com.zjcloud.common.core.page.TableDataInfo;

/**
 * 排课任务Controller
 * 
 * @author zjcloud
 * @date 2024-12-19
 */
@RestController
@RequestMapping("/academic/scheduleTask")
public class AcScheduleTaskController extends BaseController
{
    @Autowired
    private IAcScheduleTaskService acScheduleTaskService;

    /**
     * 查询排课任务列表
     */
    @PreAuthorize("@ss.hasPermi('academic:scheduleTask:list')")
    @GetMapping("/list")
    public TableDataInfo list(AcScheduleTask acScheduleTask)
    {
        startPage();
        List<AcScheduleTask> list = acScheduleTaskService.selectAcScheduleTaskList(acScheduleTask);
        return getDataTable(list);
    }

    /**
     * 导出排课任务列表
     */
    @PreAuthorize("@ss.hasPermi('academic:scheduleTask:export')")
    @Log(title = "排课任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(AcScheduleTask acScheduleTask)
    {
        List<AcScheduleTask> list = acScheduleTaskService.selectAcScheduleTaskList(acScheduleTask);
        ExcelUtil<AcScheduleTask> util = new ExcelUtil<AcScheduleTask>(AcScheduleTask.class);
        return util.exportExcel(list, "排课任务数据");
    }

    /**
     * 获取排课任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('academic:scheduleTask:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(acScheduleTaskService.selectAcScheduleTaskById(id));
    }

    /**
     * 根据学期ID获取排课任务列表
     */
    @PreAuthorize("@ss.hasPermi('academic:scheduleTask:list')")
    @GetMapping(value = "/semester/{semesterId}")
    public AjaxResult getTasksBySemester(@PathVariable("semesterId") Long semesterId)
    {
        List<AcScheduleTask> list = acScheduleTaskService.selectAcScheduleTaskBySemesterId(semesterId);
        return AjaxResult.success(list);
    }

    /**
     * 新增排课任务
     */
    @PreAuthorize("@ss.hasPermi('academic:scheduleTask:add')")
    @Log(title = "排课任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AcScheduleTask acScheduleTask)
    {
        return toAjax(acScheduleTaskService.insertAcScheduleTask(acScheduleTask));
    }

    /**
     * 修改排课任务
     */
    @PreAuthorize("@ss.hasPermi('academic:scheduleTask:edit')")
    @Log(title = "排课任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AcScheduleTask acScheduleTask)
    {
        return toAjax(acScheduleTaskService.updateAcScheduleTask(acScheduleTask));
    }

    /**
     * 删除排课任务
     */
    @PreAuthorize("@ss.hasPermi('academic:scheduleTask:remove')")
    @Log(title = "排课任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(acScheduleTaskService.deleteAcScheduleTaskByIds(ids));
    }

    /**
     * 更新任务状态
     */
    @PreAuthorize("@ss.hasPermi('academic:scheduleTask:edit')")
    @Log(title = "排课任务", businessType = BusinessType.UPDATE)
    @PutMapping("/status/{id}/{status}")
    public AjaxResult updateStatus(@PathVariable Long id, @PathVariable String status)
    {
        return toAjax(acScheduleTaskService.updateTaskStatus(id, status));
    }

    /**
     * 更新任务进度
     */
    @PreAuthorize("@ss.hasPermi('academic:scheduleTask:edit')")
    @Log(title = "排课任务", businessType = BusinessType.UPDATE)
    @PutMapping("/progress/{id}/{progress}")
    public AjaxResult updateProgress(@PathVariable Long id, @PathVariable Integer progress)
    {
        return toAjax(acScheduleTaskService.updateTaskProgress(id, progress));
    }

    /**
     * 开始任务
     */
    @PreAuthorize("@ss.hasPermi('academic:scheduleTask:edit')")
    @Log(title = "排课任务", businessType = BusinessType.UPDATE)
    @PutMapping("/start/{id}")
    public AjaxResult startTask(@PathVariable Long id)
    {
        return toAjax(acScheduleTaskService.startTask(id));
    }

    /**
     * 完成任务
     */
    @PreAuthorize("@ss.hasPermi('academic:scheduleTask:edit')")
    @Log(title = "排课任务", businessType = BusinessType.UPDATE)
    @PutMapping("/complete/{id}")
    public AjaxResult completeTask(@PathVariable Long id)
    {
        return toAjax(acScheduleTaskService.completeTask(id));
    }
}